#!/dis/sh
(date pattern) = $*
clock = /nb/clock
(th tm ts) = 0 0 0

load expr
apply {
	line1 = $1
	line2 = ${expr $1 1 +}
	earlier = `{sed -n $line1^p $clock | sed 's,	.*$,,'}
	act = `{sed -n $line1^p $clock | sed 's,^.*	,,'}
	later = `{sed -n $line2^p $clock | sed 's,	.*$,,'}
	(dh dm ds) = `{diffstardate $earlier $later}
	echo  $dh $dm $ds '	' $act | sed 's, 	 ,	,'

	ts = ${expr $ts $ds +}
	if {~ ${expr $ts 59 gt} 1} {
		ts = ${expr $ts 60 -}
		tm = ${expr $tm 1 +}
	}

	tm = ${expr $tm $dm +}
	if {~ ${expr $tm 59 gt} 1} {
		tm = ${expr $tm 60 -}
		th = ${expr $th 1 +}
	}

	th = ${expr $th $dh +}
} `{grep -n '^'$date $clock | grep $pattern | sed 's,:.*$,,'}

if {~ ${expr $ts 10 lt} 1} {ts = 0^$ts}
if {~ ${expr $tm 10 lt} 1} {tm = 0^$tm}
if {~ ${expr $th 10 lt} 1} {th = 0^$th}
echo  $th $tm $ts '	' total | sed 's, 	 ,	,'
